let path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');

const ary = ['index','other']
function htmlP(ary=[]){
  return ary.map(item=>{
    return new htmlWebpackPlugin({
      template: `./public/${item}.html`,
      filename: `${item}.html`,
      hash: true,
      chunks:[item]// 也就是说 index.html 中要引入 other.js
    })
  })
}
function entryFn(ary){
  let obj = {};
  ary.forEach(item=>{
    obj[item] =  `./src/${item}.js`
  })
  return obj
}
// console.log(htmlP(ary))

module.exports = {
  mode: 'development',// 默认  production
  // entry: './src/index.js',
  entry:{
    // index:'./src/index.js',
    // other:'./src/other.js'
    ...entryFn(ary)
  },
  output: {
    // filename: 'index.[hash:6].js',
    filename:'[name].[hash:5].js',
    path: path.resolve(__dirname, 'dist')
  },
  plugins: [
    new CleanWebpackPlugin(),
    ...htmlP(ary)
    // new htmlWebpackPlugin({
    //   template: './public/index.html',
    //   filename: 'index.html',
    //   hash: true,
    //   chunks:['index']// 也就是说 index.html 中要引入 other.js
    // }),
    // new htmlWebpackPlugin({
    //   template: './public/other.html',
    //   filename: 'other.html',
    //   // hash: true
    //   chunks:['other']
    // })
  ],
  devServer:{
    // hot:true//它是热更新； 只更新改变的组件或者模块 不会整体刷新页面
  }
}
